@extends('shared.master')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb layout-title">
                                    <li><a href="{{url('task')}}"><i class="fa fa-user fa-fw"></i> User</a></li>
                                    <li class="active" > Assign</li>
            </ol>
            {{PageData::Error()}}
            <div class="form-group">
                <label>Name</label>
                <p class="form-control-static">{{$Model->getName()}}</p>
            </div>
            <div class="form-group">
                <label>Start Date</label>
                <p class="form-control-static">{{$Model->getStartDate()}}</p>
            </div>
			<div class="form-group">
                <label>Due Date</label>
                <p class="form-control-static">{{$Model->getDueDate()}}</p>
            </div>
            <div class="form-group">
                <label>Priority</label>
                <p class="form-control-static">{{$Model->getPriority()!=null ? $Model->getPriority()->getName() : "-"}}</p>
            </div>
            <div class="form-group">
                <label>Project</label>
                <p class="form-control-static">{{$Model->getProject()!=null ? $Model->getProject()->getName() : "-"}}</p>
            </div>
            <div class="form-group">
                <label>Created By</label>
                <p class="form-control-static">{{$Model->getCreatedBy()!=null ? $Model->getCreatedBy()->getName() : "-"}}</p>
            </div>
            <div class="form-group">
                <label>Created Date</label>
                <p class="form-control-static">{{$Model->getCreatedDate()}}</p>
            </div>
            <br>
            
            {{ Form::open(array('url' => '#')) }}
                <div class="panel panel-default">
                <div class="panel-heading">
                  <h3 class="panel-title">Task Employee Assignment</h3>
                </div>
                <table class="table table-striped table-bordered table-hover" id="tblDataUser">
                    <thead>
                        <tr>
                            <th>Employee Name</th>
                            <th width="36px"></th>
                        </tr>
                    </thead>
                </table>
                <div class="panel-footer">
                <button onClick="addRowTable('tblDataUser',null);" type="button" class="btn btn-primary">Add Row</button>
                </div>
            </div>
            <script>
                var input_table = new Array(); 
		function addRowData(data, table_id) { 
                    input_table[table_id].addRow(data, true, '../../public/images/delete.png'); 
		} 

                function addRowDataWithoutDelete(data, table_id) { 
                    input_table[table_id].addRow(data); 
		} 

		function removeRow(id, table_id) { 
                    input_table[table_id].removeRow(id); 
		} 
		
		function addRowTable(table_id, obj_data) { 
                    eval('addRow' + table_id + '(table_id, obj_data);'); 
		} 

                input_table['tblDataUser'] = new azTable('tblDataUser'); 
		var cnttblDataUser = 0; 
                
                <?php 
                    $comboEmployee = '<select class="form-control" id="taskTaskAssignmentUserId_\' + cnttblDataUser + \'" name="taskTaskAssignmentUserId[]">';
                    foreach($EmployeeCombo as $key=>$item){
                                $comboEmployee .= '<option value="'.$key.'">'.$item.'</option>';
                            }
                    $comboEmployee .= '</select>';
                ?>
                    
                    
                    
                function addRowtblDataUser(table_id, obj_data) { 
                    if(obj_data == null) { 
                            obj_data = {
                                Id: '',
                                taskId: '{{$Model->getId()}}',
                                userId: ''
                            } 

                    } 
			
                    val_Id = (obj_data.Id == undefined) ? '' : obj_data.Id;
                    val_taskId = (obj_data.taskId == undefined) ? '' : obj_data.taskId;
                    val_userId = (obj_data.userId == undefined) ? '' : obj_data.userId;
                    
                    cnttblDataUser++; 
                    
                    addRowData([ 
                        "<input type='hidden' id='taskTaskAssignment_" + cnttblDataUser + "' name='taskTaskAssignment[]'  value='" + cnttblDataUser  + "' />" +
                        "<input type='hidden' id='taskTaskAssignmentId_" + cnttblDataUser + "' name='taskTaskAssignmentId[]'  value='" + val_Id  + "' />" +
                        "<input type='hidden' id='taskTaskAssignmenttaskId_" + cnttblDataUser + "' name='taskTaskAssignmenttaskId[]' value='" + val_taskId + "'>" +
                        '{{$comboEmployee}}'
                        ], 
                    table_id);
                    selectDefaultCombo('taskTaskAssignmentUserId_' + cnttblDataUser , val_userId);
                }
                @if($Model->getTaskAssignment() != null)
                    @foreach ($Model->getTaskAssignment() as $item)
                    obj_data = {
                        Id: '{{$item->getId()}}',
                        taskId: '{{$item->getTask()!=null ? $item->getTask()->getId() : "-"}}',
                        userId: '{{$item->getUser()!=null ? $item->getUser()->getId() : "-"}}'
                    } 
                    addRowTable('tblDataUser',obj_data);
                    @endforeach
                @endif
            </script>
                
            </div>
            </div>
    
            <br>
            <p>
                {{Form::submit('Save',array('class'=>'btn btn-primary',"name"=>"submit"))}}
                <button onClick="location.href='{{url('task')}}'" type="button" class="btn btn-primary">Close</button>
                {{ Form::close() }}
            </p>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>
<!-- /.container-fluid -->
    <script>
    
    </script>
@stop